package cn.xinfei.xdecision.thread;

import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Data
@RefreshScope
@Component
public class ThreadPoolExecutorConfig {
    private String name;
    private int corePoolSize;
    private int maximumPoolSize;
    private int maxQueueSize;
    private boolean semaphore=false;
    private long keepAliveTime=600;

    private boolean allowCoreThreadTimeOut=true;


    @RefreshScope
    @ConfigurationProperties(prefix = "xdecision.enginethread")
    @Bean(name = "threadPoolPropertyProperty")
    public ThreadPoolExecutorConfig threadPoolPropertyProperty() {
        return new ThreadPoolExecutorConfig();
    }


    @RefreshScope
    @ConditionalOnProperty(name = "xdecision.reentrythread.enable")
    @ConfigurationProperties(prefix = "xdecision.reentrythread")
    @Bean(name = "reentryThreadPoolPropertyProperty")
    public ThreadPoolExecutorConfig reentryThreadPoolPropertyProperty() {
        return new ThreadPoolExecutorConfig();
    }

    @RefreshScope
    @ConditionalOnProperty(name = "xdecision.nodelogthread.enable")
    @ConfigurationProperties(prefix = "xdecision.nodelogthread")
    @Bean(name = "nodeLogThreadPoolPropertyProperty")
    public ThreadPoolExecutorConfig nodeLogThreadPoolPropertyProperty() {
        return new ThreadPoolExecutorConfig();
    }

    @RefreshScope
    @ConditionalOnProperty(name = "xdecision.decisiontablethread.enable")
    @ConfigurationProperties(prefix = "xdecision.decisiontablethread")
    @Bean(name = "decisionTableThreadPoolProperty")
    public ThreadPoolExecutorConfig decisionTableThreadPoolProperty() {
        return new ThreadPoolExecutorConfig();
    }

    @RefreshScope
    @ConditionalOnProperty(name = "xdecision.decisionchallengethread.enable")
    @ConfigurationProperties(prefix = "xdecision.decisionchallengethread")
    @Bean(name = "decisionChallengeThreadPoolProperty")
    public ThreadPoolExecutorConfig decisionChallengeThreadPoolProperty() {
        return new ThreadPoolExecutorConfig();
    }

    @RefreshScope
    @ConditionalOnProperty(name = "xdecision.batchthread.enable")
    @ConfigurationProperties(prefix = "xdecision.batchthread")
    @Bean(name = "batchThreadPoolProperty")
    public ThreadPoolExecutorConfig batchThreadPoolProperty() {
        return new ThreadPoolExecutorConfig();
    }


//    @RefreshScope
//    @ConfigurationProperties(prefix = "xdecision.metainfothread")
//    @Bean(name = "metainfothreadPoolPropertyProperty")
//    public ThreadPoolExecutorConfig metainfothreadPoolPropertyProperty() {
//        return new ThreadPoolExecutorConfig();
//    }


//
//

//    @ConditionalOnProperty(prefix = "xdecision", name = "xpulsar-thread")
//    @ConditionalOnBean(ThreadPoolExecutorConfig.class)
//    @ConfigurationProperties(prefix = "xdecision.xpulsar-thread")
//    @Bean(name = "xpulsarThreadPoolPropertyProperty")
//    public ThreadPoolExecutorConfig xpulsarThreadPoolPropertyProperty() {
//        return new ThreadPoolExecutorConfig();
//    }

//    @ConfigurationProperties(prefix = "adp.logconsumerthreadpool")
//    @Bean(name = "logConsumerThreadConfig")
//    public ThreadPoolExecutorConfig logConsumerThreadConfig() {
//        return new ThreadPoolExecutorConfig();
//    }
}
